/**
 * 
 */
package ro.dta.idbi.ui;

import java.awt.Color;
import java.awt.GradientPaint;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.LayoutManager;

import javax.swing.JPanel;

/**
 * Panel with a gradient background
 * 
 * @author Tudor Dobrila
 * 
 */
public class JGradientPanel extends JPanel {

	private static final long serialVersionUID = -128282342017506326L;

	/**
	 * JGradientPanel empty constructor
	 */
	public JGradientPanel() {
		super();
	}

	/**
	 * JGradientPanel class constructor
	 * 
	 * @param layout
	 *            Layout used for this panel
	 */
	public JGradientPanel(final LayoutManager layout) {
		super(layout);
	}

	@Override
	protected void paintComponent(final Graphics graphics) {
		if (!isOpaque()) {
			super.paintComponent(graphics);
			return;
		}

		final Graphics2D g2d = (Graphics2D) graphics;
		final int width = getWidth();
		final int height = getHeight();
		final Color color1 = new Color(216, 222, 224);
		final Color color2 = color1.brighter();
		final GradientPaint gradient = new GradientPaint(0, 0, color1, 0, height, color2);

		g2d.setPaint(gradient);
		g2d.fillRect(0, 0, width, height);
	}
}
